//
//  MainTabBarController.m
//  EcmDoctor
//
//  Created by 张进 on 15/6/1.
//  Copyright (c) 2015年 张进. All rights reserved.
//

#import "MainTabBarController.h"
#import "AppUtils.h"
#import "DiagnoseController.h"
#import "MyClinicController.h"
#import "MyInfoController.h"
#import "MyClinic/MyClinicTabController.h"
#import "RefreshToken.h"
#import "AppDelegate.h"
#import "badgeUrl.h"

@interface MainTabBarController ()<UITabBarControllerDelegate>

@property (nonatomic, strong) id coller;
@property (nonatomic, strong) AppDelegate *app;

@end

@implementation MainTabBarController

#warning clinic online tel diagonse 页面传值 1:重写滚动视图 2:隐藏详情页面的治疗方案   3:改变详情页面底部布局   4:隐藏推荐治疗方案页面的详情  （根据代码为准）

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:55/255.0 green:51/255.0 blue:49/255.0 alpha:1.0]];
    // Do any additional setup after loading the view.
    
    self.delegate = self;
    self.navigationController.
    self.view.backgroundColor = [UIColor clearColor];
    self.navigationController.view.backgroundColor = [AppUtils getBackground];
    [self.navigationItem setHidesBackButton:YES];

    self.navigationController.navigationBar.translucent = NO;
    
    //清除tabbar上边的黑线
    [self.tabBar setBackgroundImage:[self createImageWithColor:[UIColor clearColor]]];
    [self.tabBar setShadowImage:[self createImageWithColor:[UIColor clearColor]]];
    //tabbar背景图
    [self.tabBar setBackgroundImage:[[UIImage imageNamed:@"bg_footer"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    
    
    //badge值
    _app = [UIApplication sharedApplication].delegate;
    [self.view addSubview:_app.diagnoseBadge];
    
    NSArray *items = self.tabBar.items;
    
    //免费咨询图标
    UITabBarItem *diagnosisItem = [items objectAtIndex:0];
    diagnosisItem.image = [[UIImage imageNamed:@"glasses_normal"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    diagnosisItem.selectedImage =[[UIImage imageNamed:@"glasses_press"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    diagnosisItem.title = nil;
    //个人诊所图标
    UITabBarItem *myClinicItem = [items objectAtIndex:1];
    myClinicItem.image = [[UIImage imageNamed:@"home_normal"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    myClinicItem.selectedImage =[[UIImage imageNamed:@"home_press"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    myClinicItem.title = nil;
    //我的图标
    UITabBarItem *myInfoItem = [items objectAtIndex:2];
    myInfoItem.image = [[UIImage imageNamed:@"my_normal"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    myInfoItem.selectedImage =[[UIImage imageNamed:@"my_press"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    myInfoItem.title = nil;
    
    
    [self performSegueWithIdentifier:@"enterTheUserView" sender:self];
    
    
//    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(hidden) name:@"hidden"object:nil];
}
//- (void)hidden {
//    self.navigationController.navigationBar.hidden = YES;
//}

 
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
    if ([[UIDevice currentDevice].systemVersion floatValue] >= 6.0) {
        
        //需要注意的是self.isViewLoaded是必不可少的，其他方式访问视图会导致它加载 ，在WWDC视频也忽视这一点。
        
        if (self.isViewLoaded && !self.view.window)// 是否是正在使用的视图
        {
            // Add code to preserve data stored in the views that might be
            // needed later.
            
            // Add code to clean up other strong references to the view in
            // the view hierarchy.
            self.view = nil;// 目的是再次进入时能够重新加载调用viewDidLoad函数。
        }
        
    }
    // Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (UIImage *)createImageWithColor:(UIColor *)color
{
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return theImage;
}

#pragma UITabBarControllerDelegate
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
    
  
    if ([viewController isKindOfClass:[DiagnoseController class]]) {
        
        self.navigationItem.title = @"义诊";
        self.navigationController.navigationBar.hidden = NO;
        //tableview不会向上移动
        self.navigationController.navigationBar.translucent = NO;
        self.navigationItem.rightBarButtonItem = nil;
        _app.diagnoseBadge.frame = CGRectMake(kScreenWidth/3-38, kScreenHeight-114, 18, 18);
        
    }else if ([viewController isKindOfClass:[MyClinicTabController class]]){
        
        self.navigationItem.title = @"个人诊所";
        self.navigationController.navigationBar.hidden = NO;
        //tableview不会向上移动
        self.navigationController.navigationBar.translucent = NO;
        _app.diagnoseBadge.frame = CGRectMake(kScreenWidth/3-38, kScreenHeight-114, 18, 18);
        
    }else if ([viewController isKindOfClass:[MyInfoController class]]){
        
        self.navigationItem.title = @"我的";
        self.navigationController.navigationBar.translucent = YES;
        _app.diagnoseBadge.frame = CGRectMake(kScreenWidth/3-38, kScreenHeight-50, 18, 18);
        //tableview向上移动
//        self.navigationController.navigationBar.hidden = YES;
    }
}


@end
